<template>
  <div class="update-gender">
    <van-picker
      show-toolbar
      :columns="columns"
      :default-index="defaultIndex"
      @cancel="$emit('close')"
      @confirm="onConfirm"
      @change="onGenderChange"
    />
  </div>
</template>
<script>
import {updategetUserProfile} from '@/api/user'
export default {
  name: "UpdateGender",
  props:{
      value:{
        type:Number,
        required:true
      }
  },
  data(){
      return{
        columns:['男','女'],
        defaultIndex:this.value
      }
  },
   methods: {
     onGenderChange(picker,value,index){
         this.defaultIndex=index
       }, 
     async onConfirm () {
       this.$toast.loading({
           message:'保存中',
           forbidclick:true
       })
           await updategetUserProfile({
              gender:this.defaultIndex
            })
            this.$toast.success('保存成功')
            this.$emit('input',this.defaultIndex)
            this.$emit('close')
    }
  }
}
</script>